package com.uvnos4j.matilda.system.controller;

import com.uvnos4j.matilda.commons.dto.Result;
import com.uvnos4j.matilda.commons.utils.TreeUtil;
import com.uvnos4j.matilda.system.domain.SysAcl;
import com.uvnos4j.matilda.system.domain.SysUser;
import com.uvnos4j.matilda.system.service.SysAclService;
import com.uvnos4j.matilda.system.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 首页控制器
 * <p>
 * Description:首页控制器
 * </p>
 *
 * @author Guo.wl
 * @version v1.0.0
 * @see com.uvnos4j.matilda.system.controller
 * @since 2020-08-31 22:36:29
 */
@Controller
public class IndexController {
    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private SysAclService sysAclService;

    @GetMapping("/welcome")
    public String welcome() {
        return "welcome";
    }

    /**
     * 获取当前登录用户的信息
     *
     * @return 当前登录用户的信息
     */
    @ResponseBody
    @GetMapping("/getUserInfo")
    public Result getUserInfo() {
        SysUser sysUser = sysUserService.getUserInfo();
        return Result.success(sysUser);
    }

    /**
     * 读取用户菜单
     *
     * @return 用户菜单
     */
    @ResponseBody
    @GetMapping("/findMenuByUser")
    public Result findMenuListByUser() {
        SysUser sysUser = sysUserService.getUserInfo();
        List<SysAcl> aclList = sysAclService.findByUserId(sysUser.getId());
        List<SysAcl> menuList = TreeUtil.bulidTree(aclList);
        return Result.success(menuList);
    }
}
